package product.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import product.entity.Product;
import product.service.IProductService;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lh
 * @since 2020-08-08
 */
@RestController
@RequestMapping
@Slf4j
public class ProductController {
    @Autowired
    private IProductService productService;

    @GetMapping("/product/{id}")
    public Product getByCode(@PathVariable Integer id) {
        log.info("get product detail,id is :{}", id);
        return productService.getById(id);
    }

    @PostMapping("/product/update")
    public boolean update(Product Product) {
        log.info("update product:{}", Product);
        return productService.updateById(Product);
    }

    @PostMapping("/product/insert")
    public boolean insert(Product Product) {
        log.info("insert product:{}", Product);
        return productService.save(Product);
    }

    @PostMapping("/product/delete")
    public boolean delete(@RequestParam Integer id) {
        log.info("delete product,id is {}", id);
        return productService.removeById(id);
    }

    @PostMapping("/product/deduct")
    public boolean deduct(String productCode, Integer count) {
        log.info("product deduct:{},{}", productCode, count);
        return productService.deduct(productCode, count);
    }

}
